import wepy from 'wepy';

export default class extends wepy.mixin {
    components = {};

    data = {
        // 分类列表
        mCateList: [],
        // 一级列表初始激活
        active: 0,
        // 默认高度
        wh: 568,
        // 二级分类
        mSecondCateList: []
    };

    async fetchCategoryData() {
        const { meta, message } = (await wepy.get('/categories')).data;
        console.log(message);

        if (meta.status !== 200) return wepy.baseToast();
        this.mCateList = message;
        this.mSecondCateList = this.mCateList[0].children;
        console.log(this.mSecondCateList);

        // 提示刷新
        this.$apply();
    }

    async getWindowHeight() {
        const res = await wepy.getSystemInfo();
        console.log(res);
        if (res.errMsg === 'getSystemInfo:ok') {
            this.wh = res.screenHeight;
            this.$apply();
        }
    }
    computed = {};

    methods = {
        onChange(e) {
            this.mSecondCateList = this.mCateList[e.detail].children;
            console.log(this.mSecondCateList);
        }
        // // 点击楼层中的item跳转页面
        // goProductList(url) {
        //     console.log("dddddddddddddd");

        //     console.log(url);

        //     // wepy.navigateTo({
        //     //     url
        //     // });
        // }
    };

    events = {};

    onLoad() {
        this.fetchCategoryData();
        this.getWindowHeight();
    }
}